/*
 * Danny Wu 2/9/2014
 */

package post2;
import java.util.Enumeration;
/**
 * Store holds all the information about each product and the items itself.
 */
public class Store {
    //all the information about items sold in the store
    ProductCatalog catalog;
    //all the item in the store
    Stock stock;
    //the register where the customer process their transaction
    Post register;
    //the name of the store
    String storeName;
    
    /**
     * constructor for the Store class.
     * @param name the name of the store
     */
    public Store(String name){
        this.storeName=name;
    }
    
    /**
     * initialize the catalog in the store
     * @param newCatalog the product catalog you want to the store to have
     */
    public void initCatalog(ProductCatalog newCatalog){
        this.catalog=newCatalog;
    }
    
    /**
     * initialize the stock from the product catalog in the store
     */
    public void initStock(){
        Enumeration allUPC=catalog.getAllUPC();
        this.stock=new Stock();
        String currentUPC;
        while(allUPC.hasMoreElements()){
            currentUPC=allUPC.nextElement().toString();
            this.stock.addToStock(currentUPC,new TransactionItem(currentUPC,0.0));
        }
    }
    
    /**
     * initialize the post for the store
     */
    public void initPost(){
        this.register=new Post(this);
    }
    
    /**
     * Checks if the given upc string is a valid upc in the store
     * @param upc the upc string to be checked
     * @return true if the upc is valid and false if the upc is invalid
     */
    public boolean validateUPC(String upc){
        return this.catalog.hasProduct(upc);
    }
    
    /**
     * retrieves an Item object corresponding to the given upc string
     * @param upc the upc string that correspond to the item you want to 
     * retrieve
     * @return an Item object that correspond to the given string
     */
    public TransactionItem getItem(String upc){
        return stock.getItem(upc);
    }
    
    /**
     * retrieves the product specs of a given upc string
     * @param upc the upc string that you want the product spec of
     * @return a ProductSpec object that correspond to the given upc string
     */
    public ProductSpec getProductSpec(String upc){
        return this.catalog.getProductSpec(upc);
    }
    
    /**
     * retrieves the store name of this store object
     * @return a String of the stores name
     */
    public String getStoreName(){
        return this.storeName;
    }
    
    /**
     * retrieves the post from the store
     * @return a post object from the store
     */
    public Post getPost(){
        return this.register;
    }
    
    public ProductCatalog getProductCatalog() {
        return catalog;
    } 
}
